import request from '@/utils/request'
import type { PermissionResponseData, MenuParams, ResponseData } from './type'

enum API {
  // 获取全部菜单与按钮的标识数据
  ALLPEARMISSION_URL = '/admin/acl/permission',
  // 新增菜单的接口
  ADDMENU_URL = '/admin/acl/permission/save',
  // 修改菜单的接口
  UPDATEMENU_URL = '/admin/acl/permission/update',
  // 删除已有的菜单
  DELETEMENU_URL = '/admin/acl/role/remove/',
}

// 获取菜单数据
export const reqAllPermission = () =>
  request.get<any, PermissionResponseData>(API.ALLPEARMISSION_URL)
// 新增或修改菜单的方法
export const reqAddOrUpdateMenu = (data: MenuParams) => {
  if (data.id) {
    return request.put<any, ResponseData>(API.UPDATEMENU_URL, data)
  } else {
    return request.post<any, ResponseData>(API.ADDMENU_URL, data)
  }
}
// 删除某个已有的菜单
export const reqRemoveMenu = (id: number) =>
  request.delete<any, ResponseData>(API.DELETEMENU_URL + id)
